﻿/*
	Copyright © Bogdan Kobets 2011
	http://ElasticLogic.com
*/

using System;
using System.Collections.Generic;
using ElasticLogic.TagsMarker.Concepts;
using ElasticLogic.TagsMarker.Filter;

namespace ElasticLogic.TagsMarker.Collections
{

	public sealed class EntitiesCollection<E> : CommonCollection<E>
		where E : class
	{

		public EntitiesCollection()
			: base(true)
		{
		}

		public List<E> Used
		{
			get { return Marker<E>.GetUsingEntities(true); }
		}

		public List<E> Unused
		{
			get { return Marker<E>.GetUsingEntities(false); }
		}

		public bool Add(E item)
		{
			return base.AddItem(item);
		}

		public bool Remove(E item)
		{
			if (base.Contains(item))
			{
				Marker<E>.ClearEntityTags(item);
				return base.RemoveItem(item);
			}
			else
				return false;
		}

		public void Clear()
		{
			foreach (E entity in base.Items)
			{
				this.Remove(entity);
			}
		}

		public List<E> ByTag(Tag<E> tag)
		{
			return Marker<E>.GetTagEntities(tag);
		}

		public List<E> ByCategory(Category<E> category)
		{
			return Marker<E>.GetCategoryEntities(category);
		}

		public List<E> Select(FilterRule rule)
		{
			throw new NotImplementedException();
		}

	}

}
